package cn.hg.jfsa.manage.directive;

import cn.hg.base.jfinal.directive.BaseDirective;
import cn.hg.base.jfinal.directive.annotation.JfsaDirective;
import cn.hg.jfsa.model.JfsaAdmin;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;

import java.util.List;
import java.util.Map;

@JfsaDirective("adminList")
public class AdminListDirective extends BaseDirective {

	/* (non-Javadoc)
	 * @see cn.hg.base.jfinal.directive.BaseDirective#onRender(com.jfinal.template.Env, com.jfinal.template.stat.Scope, com.jfinal.template.io.Writer)
	 */
	@Override
	public void onRender(Env env, Scope scope, Writer writer) {
		Map<String, Object> paraMap = this.getAssignedParaMap(scope);

		List<JfsaAdmin> list = CacheKit.get("jfsaAdmin", "adminList_" + paraMap.toString(), new IDataLoader() {
			@Override
			public Object load() {
				SqlPara sqlPara = JfsaAdmin.DAO.getSqlPara("system.findAdmin", paraMap);
				return JfsaAdmin.DAO.find(sqlPara);
			}
		});
		scope.setLocal("adminList", list);

		renderBody(env, scope, writer);
	}

	@Override
	public boolean hasEnd() {
		return true;
	}
}
